package com.mall.user.service.impl;

import com.mall.user.model.Provinces;
import com.mall.user.mapper.ProvincesMapper;
import com.mall.user.service.IProvincesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 省份表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@Service
public class ProvincesServiceImpl extends ServiceImpl<ProvincesMapper, Provinces> implements IProvincesService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addProvinces(Provinces provinces){
        return super.save(provinces);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String provinceid){
        return super.removeById(provinceid);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateProvinces(Provinces provinces){
        return super.updateById(provinces);
    }

    @Override
    public Provinces getById(String provinceid){
        return super.getById(provinceid);
    }

    @Override
    public List<Provinces> selectList(Provinces provinces){
        return super.list(getQueryWrapper(provinces));
    }

    @Override
    public Page<Provinces> selectPage(Page<Provinces> page, Provinces provinces){
        return super.page(page, getQueryWrapper(provinces));
    }

    public LambdaQueryWrapper<Provinces> getQueryWrapper(Provinces provinces){
        return Wrappers.<Provinces>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(provinces.getProvinceid()), Provinces::getProvinceid, provinces.getProvinceid())
            .eq(ObjectUtils.isNotEmpty(provinces.getProvince()), Provinces::getProvince, provinces.getProvince())
        ;
    }
}
